package com.zhongwang.business.module.basic.controller;

import com.google.common.base.Verify;
import com.zhongwang.business.base.BaseController;
import com.zhongwang.business.common.JsonResult;
import com.zhongwang.business.module.basic.model.DictEnumModel;
import com.zhongwang.business.module.basic.model.VerifyInfoModel;
import com.zhongwang.business.module.basic.service.DictBasicService;
import com.zhongwang.business.module.basic.service.VerifyBasicService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
public class VerifyController extends BaseController {

    @Autowired
    private DictBasicService dictBasicService;
    @Autowired
    private VerifyBasicService verifyBasicService;

    /**
     * 首页跳转至审核配置页面
     *
     * @param model
     * @return
     */
    @GetMapping("/basic/verify")
    @RequiresPermissions({"basic:verify:view"})
    public String orgPage(Model model) {
        List<VerifyInfoModel> types = verifyBasicService.selectTypes();
        List<VerifyInfoModel> levels = verifyBasicService.selectLevel();
        model.addAttribute("types", types);
        model.addAttribute("levels", levels);
        return "/basicManage/verify/page";
    }


    /**
     * 获取列表
     *
     * @return
     */
    @ResponseBody
    @PostMapping("/verifyList")
    public JsonResult selectAllList(VerifyInfoModel verify) {
        startPage();
        List<VerifyInfoModel> list = verifyBasicService.findByCondition(verify);
        return jsonResult(list);
    }


    /** 添加审核配置 */
    @ResponseBody
    @PostMapping("/verifySave")
    public JsonResult save(VerifyInfoModel verify) {
        return isNotNull(verifyBasicService.saveVerify(verify));
    }

    /** 修改审核配置 */
    @ResponseBody
    @PostMapping("/verifyUpdate")
    public JsonResult update(VerifyInfoModel verify) {
        return isNotNull(verifyBasicService.updateVerify(verify));
    }





}